package framework.states;

import java.io.File;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.StateBasedGame;

import framework.C;

public class WelcomeScreen extends BackableState {

	private boolean buttonPressed;
	
	public static final int ID = 0;
	
	private Image title;
	
	private Sound sound;
	
	private Music music;
	
	@Override
	public void init(GameContainer gc, StateBasedGame delta)
			throws SlickException {
		title = new Image(C.ASSETS_FOLDER + File.separator + "title.jpg");
		this.sound = new Sound(C.ASSETS_FOLDER + "explosion.ogg");
		this.music = new Music(C.ASSETS_FOLDER + "music.ogg");
		setPreviousState(null);
	}

	@Override
	public void render(GameContainer gc, StateBasedGame game, Graphics g)
			throws SlickException {
		g.setColor(Color.white);
		title.draw(0, 0, gc.getWidth(), gc.getHeight());
	}

	@Override
	public void update(GameContainer gc, StateBasedGame game, int delta)
			throws SlickException {
		if (buttonPressed) {
			this.sound.play();
			game.enterState(Menu.ID);
		}
	}

	@Override
	public int getID() {
		return ID;
	}
	
	@Override
	public void controllerButtonPressed(int controller, int button) {
		super.controllerButtonPressed(controller, button);
		buttonPressed = true;
	}


	@Override
	public void keyPressed(int key, char c) {
		super.keyPressed(key, c);
		buttonPressed = true;
	}

	@Override
	public void enter(GameContainer container, StateBasedGame game)
			throws SlickException {
		super.enter(container, game);
		this.buttonPressed = false;
		//this.music.play();
    }
}
